package com.example.sharding.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sharding.enerty.TOrder;
import com.example.sharding.service.TOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单表
 * </p>
 *
 * @author 杨二狗
 * @since 2022-03-06 15:10:34
 */
@Api(tags = "订单表")
@RestController
@RequestMapping("/t-order")
@Slf4j
public class TOrderController {

    @Resource
    private TOrderService tOrderService;

    /**
     * 单增
     */
    @ApiOperation(value="单增",notes="备注:例如,手机号、密码都是必输项，年龄随边填，但必须是数字")
    @PostMapping("/insertTOrder")
    public ResponseEntity<Integer> insertTOrder(@RequestBody TOrder tOrder){
        try{
            int i = tOrderService.insertTOrder(tOrder);
            return new ResponseEntity<>(i, HttpStatus.OK);
        }catch (Exception e){
            log.error("调用方法:insertTOrder抛出异常:{}",e.getMessage());
            return new ResponseEntity<>(0, HttpStatus.METHOD_FAILURE);
        }
    };
    /**
     * 批量增
     */
    @ApiOperation(value="批量增",notes="备注:例如,手机号、密码都是必输项，年龄随边填，但必须是数字")
    @PostMapping("/saveBatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<TOrder> tOrder){
        try{
            boolean b = tOrderService.saveBatch(tOrder);
            return new ResponseEntity<>(b, HttpStatus.OK);
        }catch (Exception e){
            log.error("调用方法:saveBatch抛出异常:{}",e.getMessage());
            return new ResponseEntity<>(false, HttpStatus.METHOD_FAILURE);
        }
    };
    /**
     * 批量删除
     */
    @ApiOperation(value="批量删除",notes="备注:例如,手机号、密码都是必输项，年龄随边填，但必须是数字")
    @PostMapping("/deleteTOrderBatchIds")
    public ResponseEntity<Integer> deleteTOrderBatchIds(@RequestBody List<String> ids){
        try{
            int i = tOrderService.deleteTOrderBatchIds(ids);
            return new ResponseEntity<>(i, HttpStatus.OK);
        }catch (Exception e){
            log.error("调用方法:deleteTOrderBatchIds抛出异常:{}",e.getMessage());
            return new ResponseEntity<>(0, HttpStatus.METHOD_FAILURE);
        }
    };
    /**
     * 修改
     */
    @ApiOperation(value="修改",notes="备注:例如,手机号、密码都是必输项，年龄随边填，但必须是数字")
    @PostMapping("/updateTOrder")
    public ResponseEntity<Integer> updateTOrder(@RequestBody TOrder tOrder){

        try{
            int i = tOrderService.updateTOrder(tOrder);
            return new ResponseEntity<>(i, HttpStatus.OK);
        }catch (Exception e){
            log.error("调用方法:updatetOrder抛出异常:{}",e.getMessage());
            return new ResponseEntity<>(0, HttpStatus.METHOD_FAILURE);
        }
    };
    /**
     * 查询
     */
    @ApiOperation(value="查询",notes="备注:例如,手机号、密码都是必输项，年龄随边填，但必须是数字")
    @PostMapping("/selectTOrderList")
    public ResponseEntity<List<TOrder>> selectTOrderList(@RequestBody TOrder tOrder) {
        try{
            List<TOrder> tOrders = tOrderService.selectTOrderList(tOrder);
            return new ResponseEntity<>(tOrders, HttpStatus.OK);
        }catch (Exception e){
            log.error("调用方法:selectTOrderList抛出异常:{}",e.getMessage());
            return new ResponseEntity<>(new ArrayList<>(), HttpStatus.METHOD_FAILURE);
        }
    }
    /**
     * 分页查询
     */
    @ApiOperation(value="分页查询",notes="备注:例如,手机号、密码都是必输项，年龄随边填，但必须是数字")
    @PostMapping("/selectTOrderPage")
    public ResponseEntity<IPage<TOrder>> selectTOrderPage(@RequestBody TOrder tOrder){
        try{
            IPage<TOrder> tOrderIPage = tOrderService.selectTOrderPage(tOrder);
            return new ResponseEntity<>(tOrderIPage, HttpStatus.OK);
        }catch (Exception e){
            log.error("调用方法:selectTOrderPage抛出异常:{}",e.getMessage());
            return new ResponseEntity<>(new Page<>(), HttpStatus.METHOD_FAILURE);
        }
    };


}


    